package com.ljh.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ljh.pojo.User;
import com.ljh.pojo.UserBefore;
import com.ljh.pojo.Singer;
import com.ljh.pojo.admin;
import com.ljh.vo.SexVo;
import com.ljh.vo.UserVo;
import io.swagger.models.auth.In;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper extends BaseMapper<User > {

    /**
     * 通过用户id来查询id name photo
     * @param id
     * @return
     */
    @Select("select userId,userName,userPhoto from user where userId = #{id}")
    public UserVo findAUserById(Integer id);

    /**
     * 加入
     * @param userBefore
     */
    @Insert("insert into user (userName,userPassword,userSex,userPhoto) values (#{userBefore.nickName},#{userBefore.userPassword},#{userBefore.gender},#{userBefore.userPhoto})")
    public void insertUser(@Param("userBefore") UserBefore userBefore);

    /**
     * 通过密码来查询
     * @param id
     * @return
     */
    @Select("select * from user where userPassword = #{id}")
    public User findUserByPassword(String id);

    /**
     * 更新个人信息
     * @param user
     * @return
     */
    @Update("update user set userName=#{user.userName},userTelephone=#{user.userTelephone},userEmail=#{user.userEmail},userBrith=#{user.userBrith},userIntroduce=#{user.userIntroduce},userAddress=#{user.userAddress},loveStyle=#{user.loveStyle} where userId = #{user.userId}")
    public Integer UpdatePersonInfo(@Param("user") User user);

    @Update("update user set userName=#{user.userName},userSex=#{user.userSex},userTelephone=#{user.userTelephone},userEmail=#{user.userEmail},userBrith=#{user.userBrith},userIntroduce=#{user.userIntroduce},userAddress=#{user.userAddress},loveStyle=#{user.loveStyle} where userId = #{user.userId}")
    public Integer UpdatePersonInfo2(@Param("user") User user);

    /**
     * 通过id来修改照片
     * @param userPhoto
     * @param userId
     */
    @Update("update user set userPhoto = #{userPhoto} where userId = #{userId}")
    public void UpdatePersonPhoto(String userPhoto,Integer userId);

    /**
     * 通过用户id来查询用户
     * @param userId
     * @return
     */
    @Select("select * from user where userId = #{userId}")
    public User findById(Integer userId);

    /**
     * 通过singId来查找歌手信息
     * @param singId
     * @return
     */
    @Select("SELECT * FROM singer si left outer JOIN song s on s.singerId = si.singerId where s.songId = #{songId}")
    public Singer findBySongId(Integer singId);

    /**
     * 通过userId来查找user
     * @param userId
     * @return
     */
    @Select("select * from user where userId = #{userId}")
    public User findUserById(Integer userId);

    @Delete("delete from user where userId = #{userId}")
    public void deleteUserById(Integer userId);

    @Select("SELECT userSex as name ,count(*) as value from user group by userSex")
    public List<SexVo> findUserSex();

    @Select("select password,faceName from manager where password = #{password} and username = #{username}")
    public List<admin> loginMI(String password,String username);
}
